"""
计量支付
"""
import pytest
from playwright.sync_api import expect,Playwright
from Config.config import *
from Config.URL import *
import allure
from Config.AutoFlowEngine import autoflow
from Config.Base import Base
from Config.Tool import tool

# 未输入账户
@pytest.mark.业务系统
@pytest.mark.合同管理
#@pytest.mark.parametrize('case', case_data)
def test_case(playwright : Playwright) -> None:
    SetupTeardown = Base(playwright)
    SetupTeardown.goto(url)
    SetupTeardown.login(username_admin, password_admin)
    context = SetupTeardown.context
    page = SetupTeardown.page
    SetupTeardown.expect_login()
    
    allure.step("跳转计量周期URL")
    page.goto(url + url_jiliangzhouqi)
    page.get_by_role("tree").get_by_text(
        "大庄水厂、智慧谷工业园、龙港新区 应急供水工程（智慧谷工业园标段）（智慧谷工业园标段）（智慧谷工业园标段）").click()
    page.get_by_role("button", name=" 新建").click()
    zhouqi = tool.nowtime()
    page.get_by_label("新建").get_by_placeholder("请输入周期名称").fill(zhouqi)
    page.get_by_placeholder("请选择开始日期").fill(tool.nowtime("ymd"))
    page.locator("body").press("Enter")
    page.get_by_placeholder("请选择结束日期").fill(tool.nowtime("ymd",tomorrow=1))
    page.get_by_placeholder("请选择结束日期").press("Enter")
    page.get_by_placeholder("请选择所属月份").fill(tool.nowtime("ymd"))
    page.get_by_placeholder("请选择所属月份").press("Enter")
    page.get_by_placeholder("请选择周期类型").click()
    page.locator("li").filter(has_text="进度款").click()
    page.wait_for_timeout(500)
    page.get_by_role("button", name="确 定").click()
    expect(page.get_by_role("paragraph")).to_contain_text("新建成功！")
    SetupTeardown.close()


    SetupTeardown = Base(playwright)
    SetupTeardown.goto(url)
    SetupTeardown.login("shigong1", password_admin)
    context = SetupTeardown.context
    page = SetupTeardown.page
    SetupTeardown.expect_login()
    
    allure.step("跳转计量支付URL")
    page.goto(url+url_jiliangzhifu)

    SetupTeardown.select_ht("大庄水厂、智慧谷工业园、龙港新区 应急供水工程（智慧谷工业园标段）（智慧谷工业园标段）（智慧谷工业园标段）")
    page.get_by_placeholder("请选择周期").click()

    page.locator("li").filter(has_text=zhouqi).click()
    page.get_by_role("treeitem", name=" 智慧谷工业园标段施工合同").locator("span").nth(1).click()
    page.get_by_role("treeitem", name=" 水库除险加固工程").locator("span").nth(1).click()
    page.get_by_role("treeitem", name=" △培茶主坝加固工程").locator("span").nth(1).click()
    page.get_by_role("tree").get_by_text("坝顶土方开挖").click()
    page.get_by_role("button", name=" 新建").click()
    page.get_by_role("button", name=" 添加清单").click()
    page.get_by_text("选择清单").click()
    page.get_by_role("row", name="2 1.2 土方填筑（外取土，运距2.0km）压实度98").locator("span").nth(1).click()
    page.get_by_role("button", name="确定").click()
    page.get_by_role("button", name="确 定").click()
    #expect(page.get_by_role("paragraph")).to_contain_text("新建成功")
    #page.wait_for_timeout(2000)
    page.get_by_role("tab", name="计量报表").click()
    if page.get_by_role("button", name="生成").is_visible():
        page.get_by_role("button", name="生成").click()
        page.get_by_role("row", name="序号 报表名称 上次修改时间").locator("span").nth(1).click()
        page.get_by_role("button", name="确定").click()
        #expect(page.get_by_role("paragraph")).to_contain_text("生成成功")
    #page.wait_for_timeout(3000)
    if page.get_by_role("button", name="批量确认").is_visible():
        page.get_by_role("row", name="序号 报表名称 确认状态 确认人 确认时间 创建时间 操作").locator(
            "span").nth(1).click()
        page.get_by_role("button", name="批量确认").click()

    page.wait_for_timeout(2000)
    tool.starflow(page)
    page.wait_for_timeout(2000)


    autoflow(SetupTeardown,zhouqi)

    SetupTeardown.close()


